﻿<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="pagename" value="devicebind"></c:set>
<c:set var="subdirectory" scope="request" value="worker"></c:set>

<!doctype html>
<html class="no-js">
<head>
<jsp:include page="../inc/head.jsp"></jsp:include>
</head>
<body>
	<jsp:include page="../inc/header.jsp"></jsp:include>

	<div class="am-cf admin-main">

		
		<!-- content start -->
		<div class="admin-content">
			<div class="admin-content-body">
				<div class="am-cf am-padding am-padding-bottom-0">
					<div class="am-fl am-cf">
						<strong class="am-text-primary am-text-lg">${pagetitle}</strong> /
						<small>${subtitle}</small>
					</div>
				</div>

				<hr>

				<div class="am-tabs am-margin" data-am-tabs>
					<ul class="am-tabs-nav am-nav am-nav-tabs">
						<li class="am-active"><a href="#tab1">基本信息</a></li>
					</ul>

					<div class="am-tabs-bd">
						<form class="am-form"
							action="${basePath}${sessionScope.user.role_id}/devicebind"
							method="post" onsubmit="return isNull(this)">
							<input type="hidden" name="operate" value="adddevice" />
							<input type="hidden" name="longitude" value= "${longitude}" />
							<input type="hidden" name="latitude" value="${latitude}" />
							<input type="hidden" name="accuracy" value="${accuracy}" />
							<input type="hidden" name="facId" value="${facId}" />
							<input type="hidden" name="eventId" value="${eventId}" />
							<input type="hidden" name="modId" value="${modId}" />
							<div class="am-g am-margin-top">
								<div class="am-u-sm-4 am-u-md-2 am-text-right">设施</div>
								<div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
									<input type="hidden"
										value="${facDesc}"
										type="text" name="facDesc" id="facDesc"
										onkeyup="this.value=this.value.replace((/[^\w]/g)||([\u4e00-\u9fa5]),'');"
										class="am-input-sm" placeholder="请输入设施名称" readOnly="readonly">
										<span class="am-input-group-label">${facDesc}</span>
								</div>
							</div>

							<div class="am-g am-margin-top">
								<div class="am-u-sm-4 am-u-md-2 am-text-right">设备编号</div>
								<div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
									<input type="hidden"
										value="${resultStr}"
										type="text" name="resultStr" id="resultStr"
										onkeyup="this.value=this.value.replace((/[^\w]/g)||([\u4e00-\u9fa5]),'');"
										class="am-input-sm" placeholder="请输入设备编号" readOnly="readonly">
										<span class="am-input-group-label">${resultStr}</span>
								</div>
							</div>
							
							<!-- 如果GPS信号弱 -->
							<c:if test="${accuracy>'40'}">
							<a class="am-badge am-badge-danger">gps信号弱  请自助搜索并选择地点</a>
								<div class="am-g am-margin-top">
								
									<div class="am-u-sm-3 am-text-right">地名</div>
									<div class="am-u-sm-6 am-u-end col-end">
										<input type="text" name="addressMsg" id="addressMsg"
											class="am-input-sm" placeholder="请输入关键字搜索">
									</div>
									<div class="am-u-sm-3">
										<input class="am-btn am-btn-primary am-btn-xs" onclick="poiSearch('${longitude}','${latitude}')" type="button" value="搜索"/>
									</div>
								</div>
								
								<div class="am-g am-margin-top">
									<div class="am-u-sm-3 am-text-right">选择地点</div>
									<div class="am-u-sm-7 am-u-end col-end">
										<select id="poiResult" name="poiResult">
										 
										</select>
									</div>
								</div>
							</c:if>

							<div class="am-margin">
								<button type="submit" id="submit"
									class="am-btn am-btn-primary am-btn-xs">提交保存</button>
								
							</div>
						</form>
					</div>
				</div>
			</div>

			<jsp:include page="../inc/footer.jsp" />
		</div>
		<!-- content end -->
		<jsp:include page="../inc/foot.jsp" />
		<script src="assets/js/app.js"></script>
	</div>

	

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

	<!--[if (gte IE 9)|!(IE)]><!-->
	<script src="assets/js/jquery.min.js"></script>
	<!--<![endif]-->
	<script src="assets/js/amazeui.min.js"></script>
	<script src="assets/js/app.js"></script>


	<script type="text/javascript">
		/**
		 * 判断form表单是否按规定输入相关数据
		 */
		function isNull(form) {
			if (form.facDesc.value == "") {
				alert("请确认设施编号是否已输入");
				$("#facDesc").focus();
				return false;
			}
			if (form.resultStr.value == "") {
				alert("请确认设备序列号是否已输入");
				$("#resultStr").focus();
				return false;
			}
			
			if(document.getElementById("poiResult"))
			{
				if (form.poiResult.value == "") {
					alert("请先搜索并选择您所在位置");
					$("#addressMsg").focus();
					return false;
				}
			}
			
			return true;
		}

		function change() {
			$("#submit").prop('disabled', "true");
		}
		
		
		
		/**
		 *根据关键字搜索附近位置
		 */
		 function poiSearch(lng,lat){
			
			
			var name = $("#addressMsg").val();
			
			//alert(name+","+lng+","+lat);

			$.ajax({
				type:"post",
				dataType:"json",
				cache:false,
				data:{"name":name,"lng":lng,"lat":lat},
				url:"${basePath}/ajaxpoisearch",
				success:function(data){
					
					var str="<option value='' selected>请选择地点</option>";
					
					for(var index=0;index<data.length;index++){
						str=str+("<option value='"+data[index].lng+","+data[index].lat+"'>"+data[index].address+"</option>");
					}
					$("#poiResult").html("");
					$("#poiResult").html(str);
				}
				
			});
			
		}
		
	</script>
</body>
</html>
